<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>C Constraint Interface (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="C Constraint Interface (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="C Constraint Interface (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Constraints.html" rel="up" title="Constraints">
<link href="Standard-Names.html" rel="next" title="Standard Names">
<link href="Define-Constraints.html" rel="prev" title="Define Constraints">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en">
<span id="C-Constraint-Interface"></span><div class="header">
<p>
Previous: <a href="Define-Constraints.html" accesskey="p" rel="prev">Define Constraints</a>, Up: <a href="Constraints.html" accesskey="u" rel="up">Constraints</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Testing-constraints-from-C"></span><h4 class="subsection">17.8.8 Testing constraints from C</h4>
<span id="index-testing-constraints"></span>
<span id="index-constraints_002c-testing"></span>

<p>It is occasionally useful to test a constraint from C code rather than
implicitly via the constraint string in a <code>match_operand</code>.  The
generated file <samp>tm_p.h</samp> declares a few interfaces for working
with constraints.  At present these are defined for all constraints
except <code>g</code> (which is equivalent to <code>general_operand</code>).
</p>
<p>Some valid constraint names are not valid C identifiers, so there is a
mangling scheme for referring to them from C.  Constraint names that
do not contain angle brackets or underscores are left unchanged.
Underscores are doubled, each &lsquo;<samp>&lt;</samp>&rsquo; is replaced with &lsquo;<samp>_l</samp>&rsquo;, and
each &lsquo;<samp>&gt;</samp>&rsquo; with &lsquo;<samp>_g</samp>&rsquo;.  Here are some examples:
</p>
<div class="example">
<table>
<tr><td><pre class="example"><strong>Original</strong></pre></td><td><pre class="example"><strong>Mangled</strong></pre></td></tr>
<tr><td><pre class="example"><code>x</code></pre></td><td><pre class="example"><code>x</code></pre></td></tr>
<tr><td><pre class="example"><code>P42x</code></pre></td><td><pre class="example"><code>P42x</code></pre></td></tr>
<tr><td><pre class="example"><code>P4_x</code></pre></td><td><pre class="example"><code>P4__x</code></pre></td></tr>
<tr><td><pre class="example"><code>P4&gt;x</code></pre></td><td><pre class="example"><code>P4_gx</code></pre></td></tr>
<tr><td><pre class="example"><code>P4&gt;&gt;</code></pre></td><td><pre class="example"><code>P4_g_g</code></pre></td></tr>
<tr><td><pre class="example"><code>P4_g&gt;</code></pre></td><td><pre class="example"><code>P4__g_g</code></pre></td></tr>
</table>
</div>

<p>Throughout this section, the variable <var>c</var> is either a constraint
in the abstract sense, or a constant from <code>enum constraint_num</code>;
the variable <var>m</var> is a mangled constraint name (usually as part of
a larger identifier).
</p>
<dl>
<dt id="index-constraint_005fnum">Enum: <strong>constraint_num</strong></dt>
<dd><p>For each constraint except <code>g</code>, there is a corresponding
enumeration constant: &lsquo;<samp>CONSTRAINT_</samp>&rsquo; plus the mangled name of the
constraint.  Functions that take an <code>enum constraint_num</code> as an
argument expect one of these constants.
</p></dd></dl>

<dl>
<dt id="index-satisfies_005fconstraint_005fm">Function: <em>inline bool</em> <strong>satisfies_constraint_<var>m</var></strong> <em>(rtx <var>exp</var>)</em></dt>
<dd><p>For each non-register constraint <var>m</var> except <code>g</code>, there is
one of these functions; it returns <code>true</code> if <var>exp</var> satisfies the
constraint.  These functions are only visible if <samp>rtl.h</samp> was included
before <samp>tm_p.h</samp>.
</p></dd></dl>

<dl>
<dt id="index-constraint_005fsatisfied_005fp">Function: <em>bool</em> <strong>constraint_satisfied_p</strong> <em>(rtx <var>exp</var>, enum constraint_num <var>c</var>)</em></dt>
<dd><p>Like the <code>satisfies_constraint_<var>m</var></code> functions, but the
constraint to test is given as an argument, <var>c</var>.  If <var>c</var>
specifies a register constraint, this function will always return
<code>false</code>.
</p></dd></dl>

<dl>
<dt id="index-reg_005fclass_005ffor_005fconstraint">Function: <em>enum reg_class</em> <strong>reg_class_for_constraint</strong> <em>(enum constraint_num <var>c</var>)</em></dt>
<dd><p>Returns the register class associated with <var>c</var>.  If <var>c</var> is not
a register constraint, or those registers are not available for the
currently selected subtarget, returns <code>NO_REGS</code>.
</p></dd></dl>

<p>Here is an example use of <code>satisfies_constraint_<var>m</var></code>.  In
peephole optimizations (see <a href="Peephole-Definitions.html">Peephole Definitions</a>), operand
constraint strings are ignored, so if there are relevant constraints,
they must be tested in the C condition.  In the example, the
optimization is applied if operand 2 does <em>not</em> satisfy the
&lsquo;<samp>K</samp>&rsquo; constraint.  (This is a simplified version of a peephole
definition from the i386 machine description.)
</p>
<div class="example">
<pre class="example">(define_peephole2
  [(match_scratch:SI 3 &quot;r&quot;)
   (set (match_operand:SI 0 &quot;register_operand&quot; &quot;&quot;)
        (mult:SI (match_operand:SI 1 &quot;memory_operand&quot; &quot;&quot;)
                 (match_operand:SI 2 &quot;immediate_operand&quot; &quot;&quot;)))]

  &quot;!satisfies_constraint_K (operands[2])&quot;

  [(set (match_dup 3) (match_dup 1))
   (set (match_dup 0) (mult:SI (match_dup 3) (match_dup 2)))]

  &quot;&quot;)
</pre></div>

<hr>
<div class="header">
<p>
Previous: <a href="Define-Constraints.html" accesskey="p" rel="prev">Define Constraints</a>, Up: <a href="Constraints.html" accesskey="u" rel="up">Constraints</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
